package com.hello.system.controller;

import com.hello.common.core.web.controller.BaseController;
import com.hello.common.core.web.domain.AjaxResult;
import com.hello.system.service.WxContentSecurityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 内容安全检测控制器
 * 统一的内容安全检测接口，供各个模块使用
 * 
 * @author hello
 */
@RestController
@RequestMapping("/system/content")
@Slf4j
public class ContentSecurityController extends BaseController {
    
    @Autowired
    private WxContentSecurityService contentSecurityService;
    
    /**
     * 检测文本内容是否安全
     * 
     * @param params 包含content(必需)和openid(可选)的Map
     * @return 检测结果
     */
    @PostMapping("/checkText")
    public AjaxResult checkText(@RequestBody Map<String, String> params) {
        String content = params.get("content");
        String openid = params.get("openid");
        
        if (content == null || content.isEmpty()) {
            return AjaxResult.error("校验失败：content不能为空");
        }
        
        try {
            Map<String, Object> result = contentSecurityService.checkText(content, openid);
            
            if ((Boolean) result.get("pass")) {
                return AjaxResult.success("校验通过", result);
            } else {
                return AjaxResult.error((String) result.get("message"), result);
            }
        } catch (Exception e) {
            log.error("文本内容安全识别失败", e);
            return AjaxResult.error("文本内容安全识别失败: " + e.getMessage());
        }
    }
} 